
	  
using Youz.Common.Entity;
using Youz.Common.Helper;
using Youz.CreditRepay.BLL;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace Youz.CreditRepay.Manage.Handlers
{
    public partial class Member_AreaHandler : IHttpHandler, IRequiresSessionState
    {
		Member_AreaBLL bll = new Member_AreaBLL();
		
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
			
            string _type = WebHelper.Get("type");
            string result = string.Empty;
            switch (_type)
            {
                case "get":
                    result = Get();
                    break;  
                case "list":
                    result = List();
                    break;
                case "save":
                    result = Save();
                    break;
                case "delete":
                    result = Delete();
                    break;
            }
			
            context.Response.Write(result);
            context.Response.End();
        }
		
        private string Get()
        {
            Int64 AreaID = WebHelper.Post<Int64>("AreaID");
            
            return bll.GetJson(AreaID);
        }

        private string List()
        {
            int pageIndex = WebHelper.Post<int>("start");
            int pageSize = WebHelper.Post<int>("length");

            StringBuilder sb = new StringBuilder();

            //sb.AppendFormat(" 1=1 and MemberAccount='{0}'", Core.MemberAccount);
            //sb.Append(CommonHelper.GetDateQuerySql(WebHelper.Post("StartDate"), WebHelper.Post("EndDate"), "ApplyTime"));

			int total = 0;
            DataTable dt = bll.Gets(sb.ToString(), pageIndex, pageSize, out total);

            return Core.GetJsonByDataTableHaveTime(total, dt);
        }

        private string Save()
        {
            string id = WebHelper.Post("AreaID");
            bool isAdd = string.IsNullOrWhiteSpace(id);          
            Member_Area model = new Member_Area();            

            if (isAdd)
            {
            }
            else
            {
                model = bll.Get(WebHelper.Post<Int64>("AreaID"));
            }

            model.AreaName = WebHelper.Post<String>("AreaName");
			model.Memo = WebHelper.Post<String>("Memo");
			model.Creator = WebHelper.Post<String>("Creator");
			model.CreateTime = WebHelper.Post<DateTime>("CreateTime");
			model.Modifier = WebHelper.Post<String>("Modifier");
			model.ModifyTime = WebHelper.Post<DateTime>("ModifyTime");
			

            if (isAdd ? bll.Add(model) : bll.Update(model))
            {
                return Core.AjaxResult(true, AjaxResultType.Save);
            }
            else
            {
                return Core.AjaxResult(false, AjaxResultType.Save);
            }
        }
		
        private string Delete() 
        {
            if (bll.Delete(WebHelper.Post<Int64>("AreaID")))
            {
                return Core.AjaxResult(true, AjaxResultType.Delete);
            }
            else
            {
                return Core.AjaxResult(false, AjaxResultType.Delete);
            }
        }
		
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

  